cd "/Users/myra/Dropbox/NetworkParish2016/Occupational_Choice/Submission/Final_ReStat/Codes/C_ANALYSIS"

set emptycells drop
set matsize 11000

clear
insheet using movers.csv

replace avg_servant_1851 = "" if avg_servant_1851=="NA"
replace avg_child_1851 = "" if avg_child_1851=="NA"
destring avg_servant_1851, replace
destring avg_child_1851, replace

eststo clear 
logit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil, cons vce(cluster social)
eststo 
logit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil i.social, cons vce(cluster social)
eststo 
probit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil, cons vce(cluster social)
eststo 
probit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil i.social, cons vce(cluster social)
eststo 
esttab using logit.csv, replace label cells(b(star fmt(%9.3f)) se(par)) starlevels( * 0.10 ** 0.05 *** 0.010) stats(r2_a N ll ll0, fmt(%9.3f %9.0g)) aic ///
keep(sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851)

eststo clear
logit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil if sample==1, cons vce(cluster social)
eststo 
estat ic
logit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil i.social if sample==1, cons vce(cluster social)
eststo  
probit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil if sample==1, cons vce(cluster social)
eststo 
estat ic
probit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil i.social if sample==1, cons vce(cluster social)
eststo  
estat ic
esttab using logit_sample.csv, replace label cells(b(star fmt(%9.3f)) se(par)) starlevels( * 0.10 ** 0.05 *** 0.010) stats(r2_a N ll ll0, fmt(%9.3f %9.0g)) aic ///
keep(sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851)

eststo clear
logit moverp sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851 age married nchild nservant i.civil i.social if sample==1, cons vce(cluster social)
margins, dydx(sh_professional sh_artisan sh_builder sh_commercial sh_food avg_servant_1851 avg_age_1851 avg_married_1851 avg_stayerp_1851 avg_child_1851)
esttab using logit_marginal_sample.csv, replace
